/*
 * @Description: 
 * @Author: 张民鸿
 * @Date: 2021-10-11 11:13:17
 * @FilePath: /cloud-register-business/Users/zhang/Desktop/zhang/Cloud-Registration-Desk/src/components/Permission/index.tsx
 * @LastEditTime: 2021-10-18 15:48:30
 * @LastEditors: MelodyJerry
 */
import React, { useEffect, useState } from 'react';
import { useSelector } from 'react-redux';

interface PermissionProps {
    name: string
    children: JSX.Element
}
function Permission(props: PermissionProps) {
    const [visible, setVisible] = useState(false);
    const permissions: any[] = useSelector((state: any) => state.common.permissions)
    useEffect(() => {
        for (let i in permissions) {
            if (permissions[i].sourceUrl == props.name) {
                setVisible(true)
            }
        }
        return
    }, [permissions])

    return visible ? props.children : null
}
export default Permission